<template>
  <!-- 弹出框  购物车 -->
  <div class="dialog" v-if="show">
    <van-action-sheet :value="show" class="action-sheet">
      <div class="close" @click="close"><img :src="Xpng" /></div>
      <div class="dialog_area">
        <div class="goods_block">
          <span class="left">
            <!-- //119当天样式、 -->
            <!-- <div class='box' v-if="is119"> -->
            <!-- <img src="https://image.hezongyy.com/pcimage/20211109img/jtj_h5_119jx.png" alt="" /> -->
            <!-- <div class='box_price1'>119精选</div> -->
            <!-- </div> -->
            <div class='picture'> <img :src="everyDayInfo.picture" /></div>
          </span>
          <span class="right">
            <div class="text1">{{ everyDayInfo.name }}</div>
            <div class="text2">
              <!-- 显示原价   判断是不是预览价格-->
              <div  v-if="everyDayInfo.isPreview == 1">
                <span class="text2_left" v-if="type=='阶梯价'">原价：¥ {{ everyDayInfo.retailPrice }}</span>
                <span class="text2_left1" v-else>{{setPrice.setPrice(everyDayInfo.retailPrice)}}</span>
              </div>
              <div v-else>
                <span class="text2_left" v-if="type=='阶梯价'">原价：¥ {{ everyDayInfo.retailPrice }}</span>
                <span class="text2_left1" v-else>{{setPrice.setPrice(everyDayInfo.sellingPrice)}}</span>
                <span class="text2_right" v-show="everyDayInfo.activityPrice!=-1&&type!='阶梯价'">¥ {{everyDayInfo.retailPrice}}</span>
              </div>
            </div>

            <div class="text3" v-if="
                everyDayInfo.sellingPrice != -1 &&
                  everyDayInfo.tieredPricingRules &&
                  everyDayInfo.tieredPricingRules[0].priceFloor > 0 &&
                  everyDayInfo.tieredPricingRules[0].priceCeil > 0
              ">
              券后 {{ "¥" + everyDayInfo.tieredPricingRules[0].priceFloor }} -
              {{ "¥" + everyDayInfo.tieredPricingRules[0].priceCeil }}
            </div>
            <div class="text3" v-if="
                everyDayInfo.sellingPrice != -1 &&
                  everyDayInfo.tieredPricingRules &&
                  everyDayInfo.tieredPricingRules[0].priceFloor == 0 &&
                  everyDayInfo.tieredPricingRules[0].priceCeil > 0
              ">
              券后{{ "¥" + everyDayInfo.tieredPricingRules[0].priceCeil }}
            </div>

            <div class="text3" v-if="
                everyDayInfo.sellingPrice != -1 && everyDayInfo.marketPrice > 0
              ">
              建议零售价：¥{{ everyDayInfo.marketPrice }}
            </div>
          </span>
        </div>
        <div class="ladder_block" v-if="everyDayInfo.sellingPrice != -1&& everyDayInfo.tieredPricingRules">
          <div class="title">
            <!-- <span class='left' v-if="is119">119专享价</span> -->
            <span class="left">阶梯价</span>
            <span class="center" v-if="
                everyDayInfo.tieredPricingRules &&
                  everyDayInfo.tieredPricingRules[0].priceCeil > 0
              ">券后</span>
            <span class="right">购买量</span>
          </div>
          <div class="text" v-for="(item, index) of everyDayInfo.tieredPricingRules" :key="index">
            <span class="left">¥{{ item.sellingPrice }}</span>

            <span class="center" v-if="item.priceFloor > 0 && item.priceCeil > 0">{{ "¥" + item.priceFloor + "~" + "¥" + item.priceCeil }}</span>
            <span class="center" v-if="item.priceFloor == 0 && item.priceCeil > 0">{{ "¥" + item.priceCeil }}</span>

            <span class="right">{{ getNum(item.quantity, index, everyDayInfo) }}</span>
          </div>
        </div>
        <!-- //优惠信息 -->
        <div class="info_block_discount"
          v-if="everyDayInfo.goodsPriceStruct&&everyDayInfo.goodsPriceStruct.multiPrice&&(everyDayInfo.goodsPriceStruct.multiPrice.neverBuyPriceGoods||everyDayInfo.goodsPriceStruct.multiPrice.promotionInfo)">
          <div class="title">优惠</div>
          <div class='item' v-if="everyDayInfo.goodsPriceStruct.multiPrice.neverBuyPriceGoods">
            <div class='left'>首购特价</div>
            <div class='right'>{{everyDayInfo.goodsPriceStruct.multiPrice.neverBuyPriceGoods.description}}</div>
          </div>
          <div class='item' v-if="everyDayInfo.goodsPriceStruct.multiPrice.promotionInfo">
            <div class='left'>活动特价</div>
            <div class='right'>{{everyDayInfo.goodsPriceStruct.multiPrice.promotionInfo.description}}</div>
          </div>
        </div>
        <div class="info_block">
          <div class="title">产品参数</div>
          <div class="item">
            <span class="name">生产厂家</span><span class="value">{{ everyDayInfo.manufacturerName }}</span>
          </div>
          <div class="item">
            <span class="name">规格</span><span class="value">{{ everyDayInfo.specification }}</span>
          </div>
          <div class="item">
            <span class="name">效期</span><span class="value">{{ everyDayInfo.expirationDate }}</span>
          </div>
          <div class="item">
            <span class="name">生产批准</span><span class="value">{{ everyDayInfo.licenseNumber }}</span>
          </div>
          <div class="item">
            <span class="name">包装单位</span><span class="value">{{ everyDayInfo.unit }}</span>
          </div>
          <div class="item">
            <span class="name">件装量</span><span class="value">{{ everyDayInfo.piece }}</span>
          </div>
          <div class="item">
            <span class="name">中包装</span><span class="value">{{ everyDayInfo.packages }}</span>
          </div>
          <div class="item1">
            <span class="name" v-if="everyDayInfo.quantity <= 0">购买数量(库存:<span style="color:red">缺货</span>)</span>
            <span class="name" v-if="everyDayInfo.quantity > 0">购买数量(库存:{{
                everyDayInfo.quantity > 800 ? "充裕" : everyDayInfo.quantity
              }})</span>
            <span class="value">限购:</span><span class="num">{{ everyDayInfo.maxBuyNumber }}</span>
            <span class="btn">
              <div class="img" @click="goodsAdd.sub(everyDayInfo)">-</div>
              <div class="input">
                <input type="number" v-model.number="everyDayInfo.initializeMinimum" @blur="goodsAdd.onChange(everyDayInfo)" />
              </div>
              <div class="img" @click="goodsAdd.plus(everyDayInfo)">+</div>
            </span>
          </div>
        </div>
        <div class="btn_block" @click="submit(everyDayInfo)">
          <img src="../assets/image/btn.png" />
        </div>
      </div>
    </van-action-sheet>
  </div>
</template>
<script>
import { postRequest } from '../api/index'
import url from '../axios/apiUrl'
import Xpng from '@/assets/image/X.png'
export default {
  props: {
    show: {
      type: [Boolean],
      default: false,
    },
    everyDayInfo: {},
    type: String,
    is119: false,
  },
  data() {
    return {
      Xpng,
    }
  },
  mounted() {},
  methods: {
    //计算购买量
    getNum(item, index, everyDayInfo) {
      if (index == 0) {
        return item + everyDayInfo.unit + '起'
      }
      return (
        item +
        '~' +
        (everyDayInfo.tieredPricingRules[index - 1].quantity - 1) +
        everyDayInfo.unit
      )
    },
    //加入购物车
    async submit(item) {
      if (item.quantity != 0) {
        if (item.restriction == 0) {
          let res = await postRequest(url.addShopCarNew, {
            goodsId: item.id,
            itemType: item.itemType,
            goodsQuantity: item.initializeMinimum,
          })
          if (res.data.code == '000000') {
            this.$toast('加入购物车成功~')
            this.close()
          }
          if (res.data.message == '系统异常') {
            this.$toast('网络异常，请稍后再试')
          } else if (res.data.code != '000000') {
            this.close()
            this.$toast(res.data.message)
          }
        } else {
          if (item.initializeMinimum > item.maximum) {
            this.$toast('已超过最大购买量，不能加入购物车')
          } else {
            let res = await postRequest(url.addShopCarNew, {
              goodsId: item.id,
              itemType: item.itemType,
              goodsQuantity: item.initializeMinimum,
            })
            if (res.data.code == '000000') {
              this.$toast('加入购物车成功~')
              this.close()
            }
            if (res.data.message == '系统异常') {
              this.$toast('网络异常，请稍后再试')
            } else if (res.data.code != '000000') {
              this.close()
              this.$toast(res.data.message)
            }
          }
        }
      } else {
        this.$toast('该商品已售罄')
      }
    },
    close() {
      this.$emit('close')
    },
  },
}
</script>
<style lang="less" scoped>
.dialog {
  background: rgba(0, 0, 0, 0.49);
  width: 100%;
  position: fixed;
  height: 100%;
  top: 0px;
  z-index: 9999999;
  .dialog_area {
    position: relative;

    .goods_block {
      width: auto;
      height: 280px;
      padding: 63px 24px 0 24px;
      display: flex;

      .box {
        position: relative;
        z-index: 4;
        width: 280px;
        height: 280px;
        img {
          width: 100%;
          height: 100%;
        }
        .box_price1 {
          position: absolute;
          bottom: 5px;
          left: 10px;
          width: 104px;
          height: 42px;
          line-height: 42px;
          font-size: 30px;
          font-family: PingFang SC, PingFang SC-Regular;
          font-weight: 400;
          text-align: JUSTIFIED;
          background-image: linear-gradient(180deg, #ffffff 0%, #ffd313 100%);
          -webkit-background-clip: text;
          -webkit-text-fill-color: transparent;
          text-shadow: 2px 2px 4px 0px rgba(0, 0, 0, 0.5);
        }
      }

      .left {
        width: 280px;
        height: 280px;
        opacity: 1;
        background: #ffffff;
        border-radius: 8px;
        margin-right: 24px;
        .picture {
          position: absolute;
          width: 280px;
          height: 280px;
          top: 64px;
          img {
            width: 100%;
            height: 100%;
          }
        }
      }

      .right {
        flex: 1;

        .text1 {
          width: 100%;
          height: 90px;
          opacity: 1;
          font-size: 32px;
          font-family: PingFang, PingFang-Medium;
          font-weight: 500;
          text-align: justify;
          color: #333333;
          line-height: 45px;
          overflow: hidden;
          margin-bottom: 48px;
        }

        .text2 {
          padding-bottom: 6px;

          .text2_left {
            width: 120px;
            height: 40px;
            opacity: 1;
            font-size: 32px;
            font-family: PingFang, PingFang-Semibold;
            font-weight: 600;
            text-align: justify;
            color: #333;
            line-height: 40px;
          }
          .text2_left1 {
            width: 120px;
            height: 59px;
            opacity: 1;
            font-size: 42px;
            font-family: PingFang, PingFang-Semibold;
            font-weight: 600;
            text-align: justify;
            color: #ff540d;
            line-height: 59px;
          }
          .text2_right {
            height: 37px;
            opacity: 1;
            font-size: 26px;
            font-family: PingFang, PingFang-Regular;
            font-weight: 400;
            text-decoration: line-through;
            text-align: justify;
            color: #999999;
            line-height: 37px;
            padding-left: 12px;
          }
        }

        .text3 {
          width: auto;
          height: 33px;
          opacity: 1;
          font-size: 24px;
          font-family: PingFang, PingFang-Regular;
          font-weight: 400;
          text-align: justify;
          color: #666666;
          line-height: 33px;
          padding-bottom: 5px;
        }
      }
    }

    .ladder_block {
      margin: 10px 24px 12px 24px;
      width: auto;
      height: auto;
      opacity: 1;
      border: 1px solid #f34444;
      border-radius: 10px;

      .title {
        width: 100%;
        height: 60px;
        opacity: 1;
        line-height: 60px;
        background: #f34444;
        border-radius: 8px 8px 0px 0px;
        display: flex;
        color: #fff;

        .left {
          width: 30%;
          text-align: left;
          padding-left: 24px;
        }

        .center {
          text-align: left;
          flex: 1;
        }

        .right {
          width: 30%;
          text-align: left;
        }
      }

      .text {
        width: 100%;
        height: 48px;
        line-height: 48px;
        opacity: 1;
        border-radius: 8px 8px 0px 0px;
        display: flex;
        color: #f34444;
        &:last-child {
          padding-bottom: 10px;
        }

        .left {
          width: 30%;
          text-align: left;
          padding-left: 24px;
        }

        .center {
          text-align: left;
          flex: 1;
        }

        .right {
          width: 30%;
          text-align: left;
          color: #333333;
        }
      }
    }

    .btn_block {
      position: fixed;
      bottom: 0px;
      background: #fff;
      width: auto;
      height: auto;
      opacity: 1;
      margin: 0 24px;
      padding-bottom: 10px;
      z-index: 6666;

      img {
        width: 100%;
        height: 100%;
      }
    }
    .info_block_discount {
      display: inline-block;
      width: 100%;
      height: 100%;
      .title {
        width: auto;
        height: 40px;
        opacity: 1;
        font-size: 28px;
        font-family: PingFang, PingFang-Medium;
        font-weight: 500;
        text-align: justify;
        color: #333333;
        line-height: 40px;
        margin: 12px 24px;
      }
      .item {
        width: 100%;
        height: 36px;
        border-radius: 1px;
        margin-bottom: 12px;
        padding-left: 24px;
        box-sizing: border-box;

        .left {
          display: inline-block;
          width: 120px;
          height: 36px;
          background: #fc3e33;
          border-radius: 1px;
          line-height: 36px;
          text-align: center;
          color: #fff;
          font-size: 24px;
          font-family: PingFang-SC-Regular, PingFang-SC;
          font-weight: 400;
          color: #ffffff;
        }
        .right {
          padding-left: 20px;
          display: inline-block;
          width: 350px;
          height: 36px;
          line-height: 36px;
          background: #f8faff;
          border-radius: 1px;
          font-size: 24px;
          font-family: PingFang-SC-Regular, PingFang-SC;
          font-weight: 400;
          color: #333333;
        }
      }
    }

    .info_block {
      display: inline-block;
      width: 100%;
      height: 100%;
      padding-bottom: 175px;

      .title {
        width: auto;
        height: 40px;
        opacity: 1;
        font-size: 28px;
        font-family: PingFang, PingFang-Medium;
        font-weight: 500;
        text-align: justify;
        color: #333333;
        line-height: 40px;
        margin: 12px 24px;
      }

      .item {
        width: auto;
        height: 37px;
        line-height: 37px;
        opacity: 1;
        font-size: 26px;
        font-family: PingFangSC, PingFangSC-Regular;
        font-weight: 400;
        text-align: center;
        color: #666666;
        margin: 0 24px;
        box-sizing: border-box;
        margin-bottom: 19px;

        .name {
          display: inline-block;
          width: 20%;
          text-align: left;
          height: 30px;
          line-height: 30px;
        }

        .value {
          display: inline-block;
          text-align: right;
          width: 80%;
          overflow: hidden;
          height: 30px;
          line-height: 30px;
        }
      }

      .item1 {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 110px;
        margin: 0 24px;
        background: #fff;
        padding-bottom: 20px;
        text-align: left;
        height: 60px;
        line-height: 60px;
        width: auto;
        display: flex;

        .name {
          display: inline-block;
          width: 270px;
          height: 60px;
          opacity: 1;
          font-size: 26px;
          font-family: PingFang, PingFang-Regular;
          font-weight: 400;
          color: #666666;
          line-height: 60px;
          overflow: hidden;
        }

        .value {
          display: inline-block;
          width: 65px;
          height: 60px;
          opacity: 1;
          font-size: 26px;
          font-family: PingFang, PingFang-Regular;
          font-weight: 400;
          color: #666666;
          line-height: 60px;
        }

        .num {
          display: inline-block;
          width: 110px;
          height: 60px;
          line-height: 60px;
          overflow: hidden;
        }

        .btn {
          text-align: right;
          flex: 1;
          height: 60px;
          line-height: 60px;
          font-size: 40px;

          .img {
            display: inline-block;
            width: 60px;
            height: 60px;
            background: #e1e1e1;
            text-align: center;
          }

          .input {
            height: 60px;
            line-height: 60px;
            display: inline-block;
            width: 100px;
            overflow: hidden;
            vertical-align: middle;

            input {
              text-align: center;
              width: 100%;
              border: none;
            }
          }
        }
      }
    }
  }
  .action-sheet {
    .close {
      position: absolute;
      right: 24px;
      top: 16px;
      z-index: 999;
      background: #fff;

      img {
        display: inline-block;
        width: 44px;
        height: 44px;
      }
    }
  }
}
</style>
